package org.example.ReflectDemo.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;

@Slf4j
@Aspect
//@Component
public class AspectDemo {
    @Pointcut("execution(* org.example.ReflectDemo.controller.*.*(..))")
    private void pt(){}
    @Around("pt()")
    public Object doAround(ProceedingJoinPoint pjp) {
        log.info("doAround 前");
        Object result = null;
        try {
            result = pjp.proceed();
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }finally {
            log.info("doAround 后");
        }
        return result;
    }

    @Before("pt()")
    public void doBefore() {
        log.info("doBefore");
    }
    @After("pt()")
    public void doAfter() {
        log.info("doAfter");
    }
    @AfterReturning("pt()")
    public void doAfterReturning() {
        log.info("doAfterReturning ...");
    }
    @AfterThrowing("pt()")
    public void doAfterThrowing() {
        log.info("doAfterThrowing ...");
    }
}
